/*
 * @Description: 状态
 * @Author: iamsmiling
 * @Date: 2021-06-11 10:54:44
 * @LastEditTime: 2021-06-11 14:32:36
 */

import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/common_kit/color_kit.dart';
import 'package:credit_business_circle/domain/local/topic/topic_entity.dart';

enum TopicStatus { toBaAudited, displaying, failed, freeze, stop }

extension TopicStatusKit on TopicStatus {
  String get name =>
      {
        TopicStatus.toBaAudited: "待审核",
        TopicStatus.displaying: "展示中",
        TopicStatus.failed: "未通过",
        TopicStatus.freeze: "违规冻结",
        TopicStatus.stop: "暂停中"
      }[this] ??
      "";
  String get color =>
      {
        TopicStatus.toBaAudited: "#FF5B01",
        TopicStatus.displaying: "#09B4F3",
        TopicStatus.failed: "#AAAAAA",
        TopicStatus.freeze: "#333333",
        TopicStatus.stop: "#6B8DFA"
      }[this] ??
      "";

  List<TopicAction> get actions {
    if (TopicStatus.displaying == this) {
      return [
        TopicAction.changeColor,
        TopicAction.refresh,
        TopicAction.pinToTop,
        TopicAction.asHeadline,
        TopicAction.edit,
        TopicAction.stop,
        TopicAction.leaveMessage,
        TopicAction.delete
      ];
    }
    if (TopicStatus.stop == this) {
      return [
        TopicAction.changeColor,
        TopicAction.refresh,
        TopicAction.pinToTop,
        TopicAction.asHeadline,
        TopicAction.edit,
        TopicAction.putOnShelf,
        TopicAction.leaveMessage,
        TopicAction.delete
      ];
    }

    return [];
  }

  List<TopicExtraAction> get extraActions {
    if (TopicStatus.failed == this) {
      return [
        TopicExtraAction.editAgain,
        TopicExtraAction.viewFailureReason,
        TopicExtraAction.delete
      ];
    }
    if (TopicStatus.freeze == this) {
      return [TopicExtraAction.viewIllegalReason, TopicExtraAction.delete];
    }
    return [];
  }
}

enum TopicAction {
  changeColor,
  refresh,
  pinToTop,
  asHeadline,
  edit,
  stop,
  leaveMessage,
  delete,
  putOnShelf
}

extension TopicActionKit on TopicAction {
  String get name =>
      {
        TopicAction.changeColor: "变色",
        TopicAction.refresh: "刷新",
        TopicAction.pinToTop: "置顶",
        TopicAction.asHeadline: "头条",
        TopicAction.edit: "编辑",
        TopicAction.stop: "暂停",
        TopicAction.leaveMessage: "留言",
        TopicAction.delete: "删除",
        TopicAction.putOnShelf: "上架",
      }[this] ??
      "";

  String get color =>
      {
        TopicAction.changeColor: "#08ABC3",
        TopicAction.refresh: "#08ABC3",
        TopicAction.pinToTop: "#08ABC3",
        TopicAction.asHeadline: "#08ABC3",
        TopicAction.edit: "#88B903",
        TopicAction.stop: "#88B903",
        TopicAction.leaveMessage: "#88B903",
        TopicAction.delete: "#88B903",
        TopicAction.putOnShelf: "#FE5B02",
      }[this] ??
      "";
}

enum TopicExtraAction {
  editAgain,
  delete,
  viewFailureReason,
  viewIllegalReason
}

extension TopicExtraActionKit on TopicExtraAction {
  String get name =>
      {
        TopicExtraAction.editAgain: "重新编辑",
        TopicExtraAction.viewFailureReason: "未通过原因",
        TopicExtraAction.viewIllegalReason: "违规原因",
        TopicExtraAction.delete: "删除"
      }[this] ??
      "";

  String get icon =>
      {
        TopicExtraAction.editAgain: R.image.topicEditAgain,
        TopicExtraAction.viewFailureReason: R.image.topicFaliure,
        TopicExtraAction.viewIllegalReason: R.image.topicFreeze,
        TopicExtraAction.delete: R.image.topicDelete
      }[this] ??
      "";

  String get color =>
      {
        TopicExtraAction.editAgain: "#333333",
        TopicExtraAction.viewFailureReason: "#FF3D01",
        TopicExtraAction.viewIllegalReason: "#FF3D01",
        TopicExtraAction.delete: "#333333"
      }[this] ??
      "";
}

class TopicPublishmentEntity {
  late String title;

  late String no;

  late int statusCode;

  late List<TopicTagEntity> tags;

  late String createAt;

  late String updateAt;

  late String pinToTopAt;

  late int messageCount;

  bool get dateVisibile {
    if ([TopicStatus.toBaAudited, TopicStatus.failed, TopicStatus.freeze]
        .contains(status)) {
      return false;
    }
    return true;
  }

  TopicStatus get status =>
      {
        1: TopicStatus.toBaAudited,
        2: TopicStatus.displaying,
        3: TopicStatus.stop,
        4: TopicStatus.failed,
        5: TopicStatus.freeze
      }[statusCode] ??
      TopicStatus.toBaAudited;

  TopicPublishmentEntity.sample(
      {this.title = "【货拉拉】趣看资讯，多种广告业务，寻优质渠道，欢迎大佬来聊！",
      this.no = "X321546",
      this.createAt = "2020-02-20",
      this.updateAt = "2020-02-18",
      this.pinToTopAt = "置顶时间：2020-02-26",
      this.messageCount = 2,
      required this.statusCode}) {
    this.tags = [
      TopicTagEntity(
          color: ColorKit.fromHex(
            "#E3F6FD",
          ),
          text: '渠道主'),
      TopicTagEntity(
          color: ColorKit.fromHex(
            "#F2F2F2",
          ),
          text: '标签'),
      TopicTagEntity(
          color: ColorKit.fromHex(
            "#F2F2F2",
          ),
          text: '标签'),
      TopicTagEntity(
          color: ColorKit.fromHex(
            "#E3F6FD",
          ),
          text: '渠道主')
    ];
  }
}
